package pw.archipelag.templateGame {
	import flash.display.Sprite;
	import pw.archipelag.loaderGame.interfaceGame.IGame;
	import pw.archipelag.loaderGame.interfaceGame.DescriptionPlayer;
	import pw.archipelag.loaderGame.interfaceGame.skinsPanel.SkinPanelSet;
	import flash.display.Shape;
	import pw.archipelag.loaderGame.interfaceGame.skinsPanel.SkinBg;
	import pw.archipelag.loaderGame.interfaceGame.skinsPanel.SkinBtnPanel;
	import flash.geom.Point;
	import flash.utils.setTimeout;
	import pw.archipelag.loaderGame.interfaceGame.EventLoaderGame;
	import flash.utils.clearTimeout;
	
	public class TemplateGameMini extends Sprite implements IGame {
		
		private var timeoutEndGame: uint;
		
		public function TemplateGameMini(): void {}
		
		public function init(descriptionPlayer: DescriptionPlayer) {}
		
		//oprogramowanie interfejsu
		
		public function get nameGame(): String {
			return "Gra Archipelag";
		}
		
		public function get classMcHelp(): Class {
			return null;
		}
		
		public function get skinPanelSet(): SkinPanelSet {
			var radiusForScaling: Number = 10;
			var shapeBgBtnPanel: Shape = new Shape();
			shapeBgBtnPanel.graphics.beginFill(0xBBBBBB, 0.8);
			shapeBgBtnPanel.graphics.drawRoundRectComplex(0, 0, 100, 100, radiusForScaling, radiusForScaling, radiusForScaling, radiusForScaling);
			shapeBgBtnPanel.graphics.endFill();
			var skinBg: SkinBg = new SkinBg(shapeBgBtnPanel, 1, radiusForScaling)
			var skinBtnPanel: SkinBtnPanel = new SkinBtnPanel(skinBg, null, new Point(8, 4));
			return new SkinPanelSet(null, null, skinBg, null, skinBtnPanel);
		}
		
		public function start(): void {
			this.timeoutEndGame = setTimeout(this.end, 3000);
		}
		
		public function set isPauseContinue(value: uint): void {
			if (value == 0) clearTimeout(this.timeoutEndGame);
			else if (value == 1) this.timeoutEndGame = setTimeout(this.end, 3000);
		}
		
		private function end(): void {
			var scorePoints: uint = Math.floor(Math.random() * 1000);
			var scorePercent: uint = Math.round(scorePoints / 11);
			this.dispatchEvent(new EventLoaderGame(EventLoaderGame.SAVE_SCORE, {scorePoints: scorePoints, scorePercent: scorePercent}));
		}
		
	}
	
}